/**
 * Created by zhengjiachao on 2017/4/16.
 */

ADF.model.BaseModel = function(){
    ADF.model.BaseModel.superclass.constructor.call(this);
    this.parent = null;
};

ADF.model.BaseModel.PROPERTY_ADFTAG = 'adftag';
ADF.model.BaseModel.PROPERTY_ADFINSTANCEID = 'ADFInstanceID';
ADF.model.BaseModel.PROPERTY_FONTSIZE = 'fontsize';
ADF.model.BaseModel.PROPERTY_COLOR = 'color';
ADF.model.BaseModel.PROPERTY_BORDER = 'border';
ADF.model.BaseModel.PROPERTY_BACKGROUND = 'bg';
ADF.model.BaseModel.PROPERTY_TITLE = 'title';
ADF.model.BaseModel.PROPERTY_NAME = 'name';
ADF.model.BaseModel.PROPERTY_CONFIG = 'config';

COM.util.defineClass(ADF.model.BaseModel, AGEF.BaseModel,{

    initModel: function() {
        ADF.model.BaseModel.superclass.initModel.call(this);
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_NAME, this._getName(), "", true, "名称"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_ADFTAG, "", "", true, "ADFTag"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_FONTSIZE, "", "", true, "字号"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.ColorPropertyDescriptor(ADF.model.BaseModel.PROPERTY_COLOR, "#000000", "", true, "字体颜色"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_BORDER, "1px solid #000", "", true, "边框"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.ColorPropertyDescriptor(ADF.model.BaseModel.PROPERTY_BACKGROUND, "#ffffff", "", true, "背景颜色")); 
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_TITLE, "", "", true, "提示信息"));
        this.addPropertyDescriptor(new ADF.propertyDescriptor.DefaultPropertyDescriptor(ADF.model.BaseModel.PROPERTY_CONFIG, "", "", false, "控件配置"));
    },

    _getName : function(){
        return 'base';  
    },

    serialize:function(){
        var jsonObject = JSON.parse(ADF.model.BaseModel.superclass.serialize.call(this));
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_ADFTAG);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_COLOR);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BORDER);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BACKGROUND);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_FONTSIZE);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_TITLE);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_NAME);
        this._serializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_CONFIG);
        this.fillSerializedJson(jsonObject);
        return COM.util.ObjUtil.stringify(jsonObject);
    },

    _serializeProp : function(jsonObject, key){
        if(this.getPropertyDescriptor(key)){
            jsonObject[key]=this.getPropertyDescriptor(key).serialize();
        }
    },

    setBorder: function(border) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_BORDER, border);
    },
    getBorder: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_BORDER);
    },
    setColor: function(color) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_COLOR, color);
    },
    getColor: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_COLOR);
    },
    setBackground: function(bg) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_BACKGROUND, bg);
    },
    getBackground: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_BACKGROUND);
    },
    setFontsize: function(fontsize) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_FONTSIZE, fontsize);
    },
    getFontsize: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_FONTSIZE);
    },
    setTitle: function(title) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_TITLE, title);
    },
    getTitle: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_TITLE);
    },
    setName: function(name) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_NAME, name);
    },
    getName: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_NAME);
    },
    setConfig: function(config) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_CONFIG, config);
    },
    getConfig: function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_CONFIG);
    },


    setParent: function(parent){
        this.parent = parent;
    },

    removeParent: function(){
        this.parent = null;
    },

    getParent: function(){
        return this.parent;
    },

    getADFTag : function() {
        return this.getPropertyValue(ADF.model.BaseModel.PROPERTY_ADFTAG);
    },
    setADFTag: function(id) {
        this.setPropertyValue(ADF.model.BaseModel.PROPERTY_ADFTAG, id);
    },

    fillSerializedJson : function(jsonObject){

    },

    deserialize:function (jsonString) {
        var jsonObject = ADF.model.BaseModel.superclass.deserialize.call(this, jsonString);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_ADFTAG);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BORDER);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_COLOR);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_BACKGROUND);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_FONTSIZE);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_TITLE);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_NAME);
        this._deserializeProp(jsonObject, ADF.model.BaseModel.PROPERTY_CONFIG);
        this._deserialize(jsonObject);
    },


    _deserialize:function(jsonObject){

    },

    
    clone: function() {
        var newModel = ADF.model.BaseModel.superclass.clone.call(this);
        newModel.id = undefined;
        return newModel;
    }
});